package com.jxw.launcher.view.brokenrecyclerview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import com.jxw.launcher.R;
import com.jxw.launcher.model.UserKnowledgeBean;
import com.jxw.utils.ScreenUtils;

/* loaded from: classes.dex */
public class Item1 extends View {
    private UserKnowledgeBean.DataBean currentValue;
    private int currentY;
    private boolean drawLeftLine;
    private boolean drawRightLine;
    private UserKnowledgeBean.DataBean lastValue;
    private int lastY;
    private Context mContext;
    private Paint mPaint;
    private int maxValue;
    private int minValue;
    private UserKnowledgeBean.DataBean nextValue;
    private int nextY;
    private int pointBottomY;
    private int pointTopY;
    private int pointX;
    private int pointY;
    private int totalCount;
    private int viewHeight;
    private int viewWidth;

    public Item1(Context context) {
        super(context);
        this.currentY = 15;
        this.lastY = 10;
        this.nextY = 10;
        this.pointTopY = 170;
        this.pointBottomY = 340;
        this.drawLeftLine = true;
        this.drawRightLine = true;
        this.totalCount = 0;
        this.mContext = context;
        this.pointTopY = convertDpToPixel(120);
        this.pointBottomY = convertDpToPixel(200);
        init();
    }

    private int convertDpToPixel(int i) {
        return (int) (i * this.mContext.getResources().getDisplayMetrics().density);
    }

    public void setCurrentValue(UserKnowledgeBean.DataBean dataBean, int i) {
        this.currentValue = dataBean;
        this.currentY = i;
        invalidate();
    }

    public void setMaxValue(int i) {
        this.maxValue = i;
    }

    public void setMinValue(int i) {
        this.minValue = i;
    }

    private void init() {
        this.mPaint = new Paint();
    }

    @Override // android.view.View
    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        initValues();
    }

    private void initValues() {
        this.viewHeight = getMeasuredHeight();
        this.viewWidth = getMeasuredWidth();
        this.pointX = this.viewWidth / 2;
    }

    @Override // android.view.View
    public void draw(Canvas canvas) {
        super.draw(canvas);
        int i = this.pointBottomY;
        int i2 = this.pointTopY;
        int i3 = this.maxValue;
        int i4 = this.minValue;
        this.pointY = (int) (((((i - i2) * 1.0f) / (i3 - i4)) * ((i3 - this.currentY) + i4)) + i2);
        if (this.totalCount <= 1 && this.pointY > convertDpToPixel(10000)) {
            this.pointY = convertDpToPixel(120);
        }
        Log.e("lyx", "drawPoint-1-" + this.pointY);
        drawGraph(canvas);
        drawPoint(canvas);
        drawValue(canvas);
        Log.e("Item", "" + this.lastValue + " " + this.currentValue + " " + this.nextValue);
    }

    private void drawValue(Canvas canvas) {
        float f = this.pointY - (this.mPaint.getFontMetrics().bottom * 4.0f);
        TextPaint textPaint = new TextPaint();
        textPaint.setColor(getContext().getResources().getColor(R.color.color_CDC7FF));
        textPaint.setStyle(Paint.Style.FILL);
        Context context = this.mContext;
        textPaint.setTextSize(ScreenUtils.dp2px(context, context.getResources().getDimension(R.dimen.text_size_17)));
        String knowledgename = this.currentValue.getKnowledgename();
        if (TextUtils.isEmpty(knowledgename)) {
            return;
        }
        if (this.currentY == 0) {
            if (knowledgename.length() <= 7) {
                float measureText = (this.viewWidth / 2) - (textPaint.measureText(knowledgename) / 2.0f);
                Context context2 = this.mContext;
                canvas.drawText(knowledgename, measureText, f + ScreenUtils.dp2px(context2, context2.getResources().getDimension(R.dimen.dp_100)), textPaint);
            } else if (knowledgename.length() <= 14) {
                String substring = knowledgename.substring(0, 7);
                String substring2 = knowledgename.substring(7);
                float measureText2 = (this.viewWidth / 2) - (textPaint.measureText(substring) / 2.0f);
                Context context3 = this.mContext;
                canvas.drawText(substring, measureText2, ScreenUtils.dp2px(context3, context3.getResources().getDimension(R.dimen.dp_100)) + f, textPaint);
                float measureText3 = (this.viewWidth / 2) - (textPaint.measureText(substring2) / 2.0f);
                Context context4 = this.mContext;
                float dp2px = f + ScreenUtils.dp2px(context4, context4.getResources().getDimension(R.dimen.dp_100));
                Context context5 = this.mContext;
                canvas.drawText(substring2, measureText3, dp2px + (ScreenUtils.dp2px(context5, context5.getResources().getDimension(R.dimen.dp_20)) * 1), textPaint);
            } else if (knowledgename.length() <= 21) {
                String substring3 = knowledgename.substring(0, 7);
                String substring4 = knowledgename.substring(7, 14);
                String substring5 = knowledgename.substring(14);
                float measureText4 = (this.viewWidth / 2) - (textPaint.measureText(substring3) / 2.0f);
                Context context6 = this.mContext;
                canvas.drawText(substring3, measureText4, ScreenUtils.dp2px(context6, context6.getResources().getDimension(R.dimen.dp_100)) + f, textPaint);
                float measureText5 = (this.viewWidth / 2) - (textPaint.measureText(substring4) / 2.0f);
                Context context7 = this.mContext;
                Context context8 = this.mContext;
                canvas.drawText(substring4, measureText5, ScreenUtils.dp2px(context7, context7.getResources().getDimension(R.dimen.dp_100)) + f + (ScreenUtils.dp2px(context8, context8.getResources().getDimension(R.dimen.dp_20)) * 1), textPaint);
                float measureText6 = (this.viewWidth / 2) - (textPaint.measureText(substring5) / 2.0f);
                Context context9 = this.mContext;
                float dp2px2 = f + ScreenUtils.dp2px(context9, context9.getResources().getDimension(R.dimen.dp_100));
                Context context10 = this.mContext;
                canvas.drawText(substring5, measureText6, dp2px2 + (ScreenUtils.dp2px(context10, context10.getResources().getDimension(R.dimen.dp_20)) * 2), textPaint);
            } else {
                String substring6 = knowledgename.substring(0, 7);
                String substring7 = knowledgename.substring(7, 14);
                String str = knowledgename.substring(14, 19) + "...";
                float measureText7 = (this.viewWidth / 2) - (textPaint.measureText(substring6) / 2.0f);
                Context context11 = this.mContext;
                canvas.drawText(substring6, measureText7, ScreenUtils.dp2px(context11, context11.getResources().getDimension(R.dimen.dp_100)) + f, textPaint);
                float measureText8 = (this.viewWidth / 2) - (textPaint.measureText(substring7) / 2.0f);
                Context context12 = this.mContext;
                Context context13 = this.mContext;
                canvas.drawText(substring7, measureText8, ScreenUtils.dp2px(context12, context12.getResources().getDimension(R.dimen.dp_100)) + f + (ScreenUtils.dp2px(context13, context13.getResources().getDimension(R.dimen.dp_20)) * 1), textPaint);
                float measureText9 = (this.viewWidth / 2) - (textPaint.measureText(str) / 2.0f);
                Context context14 = this.mContext;
                float dp2px3 = f + ScreenUtils.dp2px(context14, context14.getResources().getDimension(R.dimen.dp_100));
                Context context15 = this.mContext;
                canvas.drawText(str, measureText9, dp2px3 + (ScreenUtils.dp2px(context15, context15.getResources().getDimension(R.dimen.dp_20)) * 2), textPaint);
            }
        } else if (knowledgename.length() <= 7) {
            float measureText10 = (this.viewWidth / 2) - (textPaint.measureText(knowledgename) / 2.0f);
            Context context16 = this.mContext;
            canvas.drawText(knowledgename, measureText10, (f + 26.0f) - ScreenUtils.dp2px(context16, context16.getResources().getDimension(R.dimen.dp_100)), textPaint);
        } else if (knowledgename.length() <= 14) {
            String substring8 = knowledgename.substring(0, 7);
            String substring9 = knowledgename.substring(7);
            float measureText11 = (this.viewWidth / 2) - (textPaint.measureText(substring8) / 2.0f);
            float f2 = f + 10.0f;
            Context context17 = this.mContext;
            canvas.drawText(substring8, measureText11, f2 - ScreenUtils.dp2px(context17, context17.getResources().getDimension(R.dimen.dp_100)), textPaint);
            float measureText12 = (this.viewWidth / 2) - (textPaint.measureText(substring9) / 2.0f);
            Context context18 = this.mContext;
            float dp2px4 = f2 - ScreenUtils.dp2px(context18, context18.getResources().getDimension(R.dimen.dp_100));
            Context context19 = this.mContext;
            canvas.drawText(substring9, measureText12, dp2px4 + (ScreenUtils.dp2px(context19, context19.getResources().getDimension(R.dimen.dp_20)) * 1), textPaint);
        } else if (knowledgename.length() <= 21) {
            String substring10 = knowledgename.substring(0, 7);
            String substring11 = knowledgename.substring(7, 14);
            String substring12 = knowledgename.substring(14);
            float measureText13 = (this.viewWidth / 2) - (textPaint.measureText(substring10) / 2.0f);
            Context context20 = this.mContext;
            canvas.drawText(substring10, measureText13, f - ScreenUtils.dp2px(context20, context20.getResources().getDimension(R.dimen.dp_100)), textPaint);
            float measureText14 = (this.viewWidth / 2) - (textPaint.measureText(substring12) / 2.0f);
            Context context21 = this.mContext;
            Context context22 = this.mContext;
            canvas.drawText(substring12, measureText14, (f - ScreenUtils.dp2px(context21, context21.getResources().getDimension(R.dimen.dp_100))) + (ScreenUtils.dp2px(context22, context22.getResources().getDimension(R.dimen.dp_20)) * 2), textPaint);
            float measureText15 = (this.viewWidth / 2) - (textPaint.measureText(substring11) / 2.0f);
            Context context23 = this.mContext;
            float dp2px5 = f - ScreenUtils.dp2px(context23, context23.getResources().getDimension(R.dimen.dp_100));
            Context context24 = this.mContext;
            canvas.drawText(substring11, measureText15, dp2px5 + (ScreenUtils.dp2px(context24, context24.getResources().getDimension(R.dimen.dp_20)) * 1), textPaint);
        } else {
            String substring13 = knowledgename.substring(0, 7);
            String substring14 = knowledgename.substring(7, 14);
            String str2 = knowledgename.substring(14, 19) + "...";
            float measureText16 = (this.viewWidth / 2) - (textPaint.measureText(substring13) / 2.0f);
            Context context25 = this.mContext;
            canvas.drawText(substring13, measureText16, f - ScreenUtils.dp2px(context25, context25.getResources().getDimension(R.dimen.dp_100)), textPaint);
            float measureText17 = (this.viewWidth / 2) - (textPaint.measureText(str2) / 2.0f);
            Context context26 = this.mContext;
            Context context27 = this.mContext;
            canvas.drawText(str2, measureText17, (f - ScreenUtils.dp2px(context26, context26.getResources().getDimension(R.dimen.dp_100))) + (ScreenUtils.dp2px(context27, context27.getResources().getDimension(R.dimen.dp_20)) * 2), textPaint);
            float measureText18 = (this.viewWidth / 2) - (textPaint.measureText(substring14) / 2.0f);
            Context context28 = this.mContext;
            float dp2px6 = f - ScreenUtils.dp2px(context28, context28.getResources().getDimension(R.dimen.dp_100));
            Context context29 = this.mContext;
            canvas.drawText(substring14, measureText18, dp2px6 + (ScreenUtils.dp2px(context29, context29.getResources().getDimension(R.dimen.dp_20)) * 1), textPaint);
        }
    }

    public void setlastValue(UserKnowledgeBean.DataBean dataBean, int i) {
        this.lastValue = dataBean;
        this.lastY = i;
    }

    public void setNextValue(UserKnowledgeBean.DataBean dataBean, int i) {
        this.nextValue = dataBean;
        this.nextY = i;
    }

    private void drawGraph(Canvas canvas) {
        this.mPaint.setPathEffect(null);
        this.mPaint.setStyle(Paint.Style.FILL);
        this.mPaint.setColor(-4797441);
        this.mPaint.setStrokeWidth(ScreenUtils.dp2px(this.mContext, 3.0f));
        this.mPaint.setAntiAlias(true);
        this.mPaint.setPathEffect(new DashPathEffect(new float[]{ScreenUtils.dp2px(this.mContext, 15.0f), ScreenUtils.dp2px(this.mContext, 5.0f)}, 0.0f));
        if (this.drawLeftLine) {
            int i = this.currentY;
            float f = i - ((i - this.lastY) / 2.0f);
            int i2 = this.pointBottomY;
            int i3 = this.pointTopY;
            int i4 = this.maxValue;
            int i5 = this.minValue;
            canvas.drawLine(0.0f, ((((i2 - i3) * 1.0f) / (i4 - i5)) * ((i4 - f) + i5)) + i3, this.pointX, this.pointY, this.mPaint);
        }
        if (this.drawRightLine) {
            int i6 = this.currentY;
            float f2 = i6 - ((i6 - this.nextY) / 2.0f);
            int i7 = this.pointBottomY;
            int i8 = this.pointTopY;
            int i9 = this.maxValue;
            int i10 = this.minValue;
            canvas.drawLine(this.pointX, this.pointY, this.viewWidth, ((((i7 - i8) * 1.0f) / (i9 - i10)) * ((i9 - f2) + i10)) + i8, this.mPaint);
        }
    }

    private void drawPoint(Canvas canvas) {
        Bitmap decodeResource;
        Log.e("lyx", "drawPoint-2-");
        if (!this.currentValue.isNoRecord()) {
            Log.e("lyx", "drawPoint-3-");
            int parseInt = Integer.parseInt(String.valueOf(this.currentValue.getAccuracy()));
            if (parseInt >= 80) {
                decodeResource = BitmapFactory.decodeResource(this.mContext.getResources(), R.drawable.icon_jctb_jh);
            } else if (parseInt >= 60) {
                decodeResource = BitmapFactory.decodeResource(this.mContext.getResources(), R.drawable.icon_jctb_yb);
            } else {
                Log.e("lyx", "drawPoint-4-");
                decodeResource = BitmapFactory.decodeResource(this.mContext.getResources(), R.drawable.icon_jctb_jc);
            }
        } else {
            Log.e("lyx", "drawPoint-5-");
            decodeResource = BitmapFactory.decodeResource(this.mContext.getResources(), R.drawable.icon_jctb_wzd);
        }
        int width = decodeResource.getWidth();
        int height = decodeResource.getHeight();
        StringBuilder sb = new StringBuilder();
        sb.append("drawPoint-6-");
        int i = width / 2;
        sb.append(this.pointX - i);
        sb.append("*");
        int i2 = height / 2;
        sb.append(this.pointY - i2);
        Log.e("lyx", sb.toString());
        canvas.drawBitmap(decodeResource, this.pointX - i, this.pointY - i2, this.mPaint);
    }

    private void drawLine(Canvas canvas) {
        this.mPaint.setColor(-2894893);
        this.mPaint.setPathEffect(null);
        this.mPaint.setStrokeWidth(2.0f);
        this.mPaint.setStyle(Paint.Style.FILL);
        if (this.drawLeftLine) {
            canvas.drawLine(0.0f, 500.0f, this.viewWidth / 2, 500.0f, this.mPaint);
        }
        if (this.drawRightLine) {
            int i = this.viewWidth;
            canvas.drawLine(i / 2, 500.0f, i, 500.0f, this.mPaint);
        }
    }

    public void setDrawLeftLine(boolean z) {
        this.drawLeftLine = z;
    }

    public void setDrawRightLine(boolean z) {
        this.drawRightLine = z;
    }

    public void setDataTotalSize(int i) {
        this.totalCount = i;
    }
}
